import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sltchat/bean/home_info.dart';
import 'package:sltchat/page/message/message_view.dart';
import 'package:sltchat/page/mine/mine_view.dart';

import 'home_state.dart';

class HomeLogic extends GetxController {
  final HomeState state = HomeState();
  var pageController = PageController();
  @override
  void onInit() {
    super.onInit();
    state.tabData.addAll([
      HomeInfo(
          title: "对话",
          page: const MessagePage(),
          bottom: const BottomNavigationBarItem(
              tooltip: "对话",
              label: "对话",
              icon: Icon(Icons.message_outlined),
              activeIcon: Icon(Icons.message))),
      HomeInfo(
          title: "应用",
          page: Container(),
          bottom: const BottomNavigationBarItem(
              tooltip: "应用",
              label: "应用",
              icon: Icon(Icons.dashboard_outlined),
              activeIcon: Icon(Icons.dashboard))),
      HomeInfo(
          title: "我的",
          page: const MinePage(),
          bottom: const BottomNavigationBarItem(
              tooltip: "我的",
              label: "我的",
              icon: Icon(Icons.usb_outlined),
              activeIcon: Icon(Icons.usb))),
    ]);
  }

  void changePage(int index, bool byBottom) async {
    if (byBottom) {
      pageController.animateToPage(index,
          duration: const Duration(milliseconds: 200), curve: Curves.linear);
    }
    state.currentIndex.value = index;
  }
}
